<?php !defined("IN_SYSTEM") && exit("ACCESS DENY");?>
<?php include template('header');include template('top');?>
<div id="uc">
{template uc/left}
	<div id="uc_main">
		<div class="uc_tab">
			<ul>
			<li><span><a{if !isset($action)} class="on"{/if} href="{url home.php?m=order}">所有订单</a></span></li>
			<li><span><a{if $action == 'new'} class="on"{/if} href="{url home.php?m=order&a=new}">最新订单</a></span></li>
			<li><span><a{if $action == 'quick'} class="on"{/if} href="{url home.php?m=order&a=quick}">客户催单</a></span></li>
			</ul>
		</div>
		<div id="uc_contain">
		<?php if($action == 'list' || !$action):?>
			<form action="{url('home.php?m=order')}" method="POST" class="uc_search">
		搜索订单: <input type="text" name="search_field" class="txt" size="32" onclick="if(this.value=='输入订单号或手机'){ this.value='';}" onblur="if(this.value==''){ this.value='输入订单号或手机';}" id="search_field" value="{if $field}{$field}{else}输入订单号或手机{/if}"/>
			<input type="submit" class="button" value="{$lang['search']}"/>
			</form>
			<div>
			订单流程： 确认订单=>打包=>外送=>订单完成
			</div>
			<table class="uc_table od_table" >
			<tr >
			<th width="50%">
			订单信息/客户资料
			</th>
			<th width="35%">
			菜单/费用
			</th>
			<th width="15%">
			操作
			</th>
			</tr>
			
		{loop $datas $data}
			<tr id="tr{$data['pid']}">
			<td width="50%">
			
			<ul class="uorder">
			<li>
			<span class="" style="width:170px;display:inline-block;"><label>订单号:</label>{$data['txnid']} ({$orderstatus[$data['status']]})</span>   <span><label>下单时间:</label>{echo gdate('Y/m/d H:i:s',$data['created']);}</span>
			</li><li>
			<span style="width:170px;display:inline-block;"><label>手机号:</label>{$data['phone']}</span>   {if $data['changed']}<span><label>送餐时间:</label>{echo gdate('Y/m/d H:i:s',$data['changed']);}</span>{/if}
			</li><li>
			<span><label>送餐地址:</label>{$data['street']}</span>
			</li>
			{if $data['data']}
			<li><span><label>其它说明:</label>{$data['data']}</span></li>
			{/if}
			</ul>
			</td>
			<td width="35%">
			
			<ul class="uorderr" style="text-align: right; font-size:13px;">
			{loop $caidans[$data['txnid']] $c}
			<li>{$c['title']}({$c['price']}元) {$c['qty']}份</li>
			{/loop}
			<li style="border-top:1px dotted #d2d2d2;"><span><label>总价:</label>{$data['gross']}</span></li>
			</ul>
			
			
			</td>
			<td width="15%">
			<div class="orderop">
			{if $data['status']<1}
			<a href="javascript:;" onclick="order_status({$data[txnid]})">[确认]</a><br/>
			{/if}
			{if $data['status']==1}
			<a href="javascript:;" onclick="order_status({$data[txnid]})">[外送]</a><br/>
			{/if}
			{if $data['status']==4}
			<a href="javascript:;" onclick="order_status({$data[txnid]})">[结束]</a><br/>
			{/if}
			{if $data['status']<4}
			<a href="{url home.php?f=order&a=edit&id=$data[txnid]}" target="_blank" >[调整]</a><br/>
			{/if}
			{if $data['status']<5}
			<a href="javascript:;" onclick="order_cancel({$data[txnid]})" >[取消]</a><br/>
			{/if}
			</div>
			</tr>
		{/loop}
			</table>
			
			<?php echo $pager;?>
		
		<script type="text/javascript">
		function order_status(id){
			$.getJSON("home.php?m=order&a=status&id="+id+'&tm='+Math.random(),'',function(data){
				if(data.s==true){
					if(data.m){alert(data.m);}
					document.location.reload();
				}else{
				}
				});
			return false;
		}
		function order_cancel(id){
			if(!confirm('确定取消该交易?')){
				return false;
			}
			$.getJSON("home.php?m=order&a=cancel&id="+id+'&tm='+Math.random(),'',function(data){
				if(data.s==true){
					if(data.m){alert(data.m);}
					document.location.reload();
				}else{
				}
				});
			return false;
		}
		function order_fee(){//未使用该函数
			var u='{url home.php?m=order&a=fee&id=$data[txnid]&ajax=1}';
			var edit = art.dialog({
			    title: '调整菜单/费用',
			    lock: true,
			    fixed: true, //C=G.DW
			    width:560,
			    height:400,
			    padding:'0 0 0 15px',
			    cssname:'uc_editfrind',
			    content: '<iframe src="'+u+'" frameborder="0" style="width:560px;height:400px;" />'
				});
			
			return false;

		}
		function order_msg(){

		}
		</script>
		
		
		
		<?php endif;?>
		<?php if($action == 'new'):?>
			<form action="{echo url('home.php?m=order&a=new')}" method="POST" class="uc_search">
		搜索订单: <input type="text" name="search_field" class="txt" size="32" onclick="if(this.value=='输入订单号或手机'){ this.value='';}" onblur="if(this.value==''){ this.value='输入订单号或手机';}" id="search_field" value="{if $field}{$field}{else}输入订单号或手机{/if}"/>
			<input type="submit" class="button" value="{$lang['search']}"/>
			</form>
			<table class="uc_table od_table" >
		{loop $datas $data}
			<tr id="tr{$data['pid']}">
			<td width="50%">
			
			<ul class="uorder">
			<li>
			<span class="" style="width:170px;display:inline-block;"><label>订单号:</label>{$data['txnid']} (等待确认)</span>   <span><label>下单时间:</label>{echo gdate('Y/m/d H:i:s',$data['created']);}</span>
			</li><li>
			<span style="width:170px;display:inline-block;"><label>手机号:</label>{$data['phone']}</span>   {if $data['changed']}<span><label>送餐时间:</label>{echo gdate('Y/m/d H:i:s',$data['changed']);}</span>{/if}
			</li><li>
			<span><label>送餐地址:</label>{$data['street']}</span>
			</li>
			{if $data['data']}
			<li><span><label>其它说明:</label>{$data['data']}</span></li>
			{/if}
			</ul>
			</td>
			<td width="35%">
			
			<ul class="uorderr" style="text-align: right; font-size:13px;">
			{loop $caidans[$data['txnid']] $c}
			<li>{$c['title']}({$c['price']}元) {$c['qty']}份</li>
			{/loop}
			<li style="border-top:1px dotted #d2d2d2;"><span><label>总价:</label>{$data['gross']}</span></li>
			</ul>
			
			
			</td>
			<td width="15%"><a href="{url home.php?m=order&a=edit&id=$data[txnid]}" target="_blank" >[{$lang['change']}]</a></td>
			</tr>
		{/loop}
			</table>
			
			<?php echo $pager;?>
		
		<?php endif;?>
		<?php if($action == 'add' || $action == 'edit'):?>
		<form action="{url home.php?m=order&a=save}" id="cart" method="post" name="cart">
		<input type="hidden" value="{$id}" name="id"/>
		<div ><label>订单号: </label>{$orders['txnid']}</div>
		<div ><label>联系电话: </label>{$orders['phone']}</div>
		<div ><label>送餐地址: </label>{$orders['street']}</div>
		<div><label>送餐时间: </label></div>
		<div ><label>外送备注: </label>{$orders['data']}</div>
		
		<br/>
		
		
		<div style="width:500px;">
		<div class="catitle"><span class="cart1" style="width:40%">菜名</span><span style="float:left;width:15%;">单价</span><span class="cart2">数量</span><span class="cart3">总价</span></div>
		<ul id="caul">
		{loop $products $cart}
		<li class="cali" id="cali{$cart['pid']}"><span class="cart1" style="width:40%">{$cart['title']}</span><span style="float:left;width:15%;">{$cart['price']}</span><span class="cart2"><a href="javascript:;" onclick="crease({$cart['pid']},0)">-</a><font id="qty{$cart['pid']}">{$cart['qty']}</font><a href="javascript:;" onclick="crease({$cart['pid']},1)">+</a></span><span class="cart3"><font id="price{$cart['pid']}">{echo price($cart['price']*$cart['qty']);}</font></span><span class="cart4" onclick="crease({$cart['pid']},3)" title="删除">x</span></li>
		
		{/loop}
		</ul>
		<div id="catdiv" style="margin-bottom:5px;">
		<span>外送费 <input id="shippfee" style="padding:2px" size="8" ref="{echo price($orders['shipping_cost']);}" onkeyup="update_total(this)" name="shippfee" value="{echo price($orders['shipping_cost']);}"/> 元</span>
		</div>
		<div id="catdiv" style="margin-bottom:15px;">
		<span style="float:left;"><input style="padding:2px" class="input" value="请输入菜单编号" onclick="if(this.value=='请输入菜单编号')this.value='';" onblur="if(this.value=='')this.value='请输入菜单编号';" size="22" name="addcai" id="addcai"/><input style="" type="button" value="加菜" onclick="return crease(2,2);"/></span>
		<span>合计 <input id="catotal" style="padding:2px" size="8" name="catotal" value="{echo price($orders['gross']);}"/> 元</span> </div>
		</div>
		
		
		<input type="hidden" name="shopid" value="{$id}"/>
		

	<div class="clear">
     
<div class="text">
    <div class="checkout_btn_wrapper">
      <button class="button" type="submit" id="checkout_btn">提交</button>
    </div>
</div>
<div class="clear"></div>
    </div>
		</form>
<script>
		function update_total(obj){
			var total = parseFloat($('#catotal').val()) - parseFloat($(obj).attr('ref')) + parseFloat(obj.value);
			$('#catotal').val(money(total));
			$(obj).attr('ref',obj.value);
		}
		function cartextra(obj){
			$(obj).attr('onclick','dcartextra(this)');
			$('#extra').append(' '+$(obj).html());
		}
		function dcartextra(obj){
			$(obj).attr('onclick','cartextra(this)');
			var a=$('#extra').html();
			$('#extra').html(a.replace(' '+$(obj).html(),''));
		}
		function crease(id,t){
			var txnid = {$id};
			if(t==1){
				var a='increase';
			}else if(t==2){
				var id = $('#addcai').val();
				var a='add';
			}else if(t==3){
				if(!confirm('确定从订单中删除此道菜?')){return false;}
				var a='clear';
			}else{
				var a='decrease';
			}	
			$.getJSON("home.php?m=order&a="+a+"&id="+id+'&txnid='+txnid+'&tm='+Math.random(),'',function(data){
				if(data.s==true){
					if(t==2){
						$('#cali'+id).remove();
						$('#caul').append('<li class="caul" id="cali'+id+'"><span class="cart1" style="width:40%">'+data.h+'</span><span style="float:left;width:15%;">'+data.up+'</span><span class="cart2"><a href="javascript:;" onclick="crease('+id+',0)">-</a><font id="qty'+id+'">'+data.q+'</font><a href="javascript:;" onclick="crease('+id+',1)">+</a></span><span class="cart3"><font id="price'+id+'">'+money(data.p)+'</font></span><span class="cart4" onclick="crease('+id+',3)" title="删除">x</span></li>');
						$('.cart').show();
					}else if(t==3){
						if(data.t==0){
							$('#caul').html('<li></li>');
							$('.cart').hide();
							//$('#catdiv').remove();
							return ;
						}else{
							$('#cali'+id).remove();
						}	
					}else{
					$('#qty'+id).html(data.q);
					$('#price'+id).html(money(data.p));
					}
					$('#catotal').val(money(data.t));
				}else{
					alert(data.m);
				}
				});
		}
		function checkout(u){
			var content = $('.checkout').html();
			$('.checkout').html('');
			var edit = art.dialog({
			    title: '确认下单',
			    lock: true,
			    fixed: true, //C=G.DW
			    padding:'0 0 0 15px',
			    cssname:'uc_editfrind',
			    content: content,
			    closeFn: function () {
			    	$('.checkout').html(content);
			    }
				});
			
			return false;
		}
		</script>

		
				
				
		<?php endif;?>
		<?php if($action == 'del'):?>
		<?php endif;?>
		{if $action=='cate'}
		<table class="uc_table" >
				<tr>
				<th>类别名</th><th>菜单数量</th><th>{$lang['operation']}</th>
				</tr>
		{loop $datas $data}
			<tr id="tr{$data['cid']}">
			<td>{$data['catename']}</td>
			<td>{$data['total']}</td>
			<td><a href="#" target="_blank" onclick="editcate('{$data[catename]}','{$data[total]}',{$data[cid]});return false;">[{$lang['change']}]</a> <a href="{url home.php?m=order&a=del&id=$data[pid]}" onclick="return confirm_delete();" target="_blank">[{$lang['delete']}]</a></td>
			</tr>
		{/loop}
			</table>
		{/if}
	<script type="text/javascript">
	function userupdatecates(id){
		var name=$('#ucatename').val();
		var total= $("#total").val();
		if(name.length<2){alert('分类名称不能少于两个字符');return false;}
		$.getJSON("home.php?f=category&a=edit&id="+id+"&name="+encodeURIComponent(name)+"&total="+total+'&tm='+Math.random(),'',function(data){
			if(data.mstatus==true){
				window.parent.location.reload();
			}else{
				alert(data.msg);
			}
			});

	}
	function editcate(u,n,id){
		var edit = art.dialog({
		    title: '编辑类别',
		    lock: true,
		    fixed: true, //C=G.DW
		    width:350,
		    height:250,
		    padding:'10px 0 0 15px',
		    cssname:'uc_editfrind',
		    content: '<p>类别名称：<input type="text" size="30" name="ucatename" id="ucatename" value="'+u+'" class="input"/></p>'+
					 '<p>类单数量：<input type="text" size="30" name="total" id="total" value="'+n+'" class="input"/></p>'+
					 '<br/><p><input type="button" class="button" onclick="userupdatecates('+id+');" value="保存类别"/></p>'
			});
		
		return false;
	}
	</script>	
		</div>
	</div>

	<div id="uc_right"></div>
</div>
<script type="text/javascript">
function chanfefriend(u){
	var edit = art.dialog({
	    title: '<?php echo $lang['change_friend']?>',
	    lock: true,
	    fixed: true, //C=G.DW
	    width:560,
	    height:400,
	    padding:'0 0 0 15px',
	    cssname:'uc_editfrind',
	    content: '<iframe src="'+u+'" frameborder="0" style="width:560px;height:400px;" />'
		});
	
	return false;
}
function deletefrind(u,id){
	if(confirm('<?php echo $lang["confirm_delete"];?>')){
		$.getJSON(u+'&tm='+Math.random(),'',function(data){
			if(data.status==true){
				$('#'+id).hide();
			}else{
				art.dialog({fixed: true,time: 2,content: data.msg});
			}
			});
	}
	return false;
	
}
</script>

<?php include template('footer')?>